package com.etc.controller;


import com.etc.entity.Concern;
import com.etc.entity.Favorite;
import com.etc.entity.History;
import com.etc.service.FocusService;
import com.etc.service.favoriteService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("favorite")
public class FavoriteController {

    @Autowired
    favoriteService service;

    /**
     * 查询是否收藏
     * @param userId
     * @param videoId
     * @return
     */
    @RequestMapping("getFavorite")
    @ResponseBody
    public boolean getFavorite(@RequestParam("userId") String userId,
                              @RequestParam(value = "videoId",defaultValue = "")String videoId){
        return service.queryfavoriteByUserIdAndRoomId(userId, videoId);
    }

    /**
     * 添加关注
     * @param userId
     * @param videoId
     * @return
     */
    @RequestMapping("addFavorite")
    @ResponseBody
    public boolean addFavorite(@RequestParam("userId") String userId,
                              @RequestParam(value = "videoId",defaultValue = "")String videoId){
        return service.addfavorite(userId, videoId);
    }

    /**
     * 取消关注
     * @param userId
     * @param videoId
     * @return
     */
    @RequestMapping("delFavorite")
    @ResponseBody
    public boolean delFavorite(@RequestParam("userId") String userId,
                              @RequestParam(value = "videoId",defaultValue = "")String videoId){
        return service.deletefavoriteById(userId, videoId);
    }
    /**
     * 根据用户id查询所以收藏表
     * @param userId
     * @return
     */
    @RequestMapping("queryFavoriteByUserIdAndVideoId")
    @ResponseBody
    PageInfo<Favorite> queryFavoriteByUserIdAndVideoId(@RequestParam(value = "userId",defaultValue = "") String userId,@RequestParam(value = "pageNo",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "15") int pageSize){
        return service.queryFavoriteByUserIdAndVideoId(userId,pageNum,pageSize);
    }
    /**
     * 跳转收藏
     * @return
     */
    @RequestMapping("skipCollect")
    public String skipVideo(){
        return "collect/collect";
    }
}
